import static org.junit.Assert.*;

import java.sql.SQLException;

import org.junit.Test;


public class PlayerTest {

	Player player;
	Attack attack;

	@Test
	public void hpTests() {
		player = new Player();
		assertEquals("",100,player.getCurrentHP()); //checking HP is set to 100
		
		//checking setHP function
		player = new Player();
		player.setHP(50);
		assertEquals("",50,player.getCurrentHP());
		
		//checking take hits
		player = new Player();
		player.takeHit(0, 10);
		assertEquals("",100,player.getCurrentHP());
		
		player = new Player();
		player.takeHit(49, 10);
		assertEquals("",100,player.getCurrentHP());
		
		player = new Player();
		player.takeHit(50, 10);
		assertEquals("",100,player.getCurrentHP());
		
		player = new Player();
		player.takeHit(51, 10);
		assertEquals("",90,player.getCurrentHP());
		
		player = new Player();
		player.takeHit(100, 100);
		assertEquals("",0,player.getCurrentHP());
		
		//checking heal
		player = new Player();
		player.setHP(80);
		player.heal(10);
		assertEquals("",90,player.getCurrentHP());
		
		player = new Player();
		player.setHP(80);
		player.heal(20);
		assertEquals("",100,player.getCurrentHP());
		
		player = new Player();
		player.setHP(80);
		player.heal(25);
		assertEquals("",100,player.getCurrentHP());
		
		player = new Player();
		player.setHP(100);
		player.heal(10);
		assertEquals("",100,player.getCurrentHP());
				
		//checking full heal
		player = new Player();
		player.setHP(80);
		player.fullHeal();
		assertEquals("",100,player.getCurrentHP());
		
		//checking regeneration
		player = new Player();
		player.takeHit(100,20);
		assertEquals("",80,player.getCurrentHP());
		player.endTurn();
		assertEquals("",81,player.getCurrentHP());
		player.endTurn();
		assertEquals("",82,player.getCurrentHP());
		player.endTurn();
		assertEquals("",83,player.getCurrentHP());
		player.endTurn();
		assertEquals("",85,player.getCurrentHP());
		player.endTurn();
		assertEquals("",86,player.getCurrentHP());
		
		//checking complex rules
		player = new Player();
		player.takeHit(100,20);
		assertEquals("",80,player.getCurrentHP());
		player.heal(10);
		assertEquals("",90,player.getCurrentHP());
		player.takeHit(100, 20);
		assertEquals("",70,player.getCurrentHP());
		player.heal(10);
		assertEquals("",80,player.getCurrentHP());
		player.heal(15);
		assertEquals("",95,player.getCurrentHP());
		player.heal(10);
		assertEquals("",98,player.getCurrentHP());
		player.takeHit(100, 10);
		assertEquals("",88,player.getCurrentHP());
		player.heal(10);
		assertEquals("",97,player.getCurrentHP());
		
	}
	
	@Test
	public void weaponTest()
	{
		//basic testing of dice rolls, as random number just limited testing to check for major failures
		int x;
		x = GameEngine.roll (6);
		assertTrue(x > 0 && x <= 6);
		
		x = GameEngine.roll(3, 4);
		assertTrue(x >= 3 && x <= 12);
		
		x = GameEngine.roll(2, 8, 2);
		assertTrue(x >= 4 && x <= 18);
		
		//testing constructor and get methods off Attack class
		attack = new Attack(50, 10);
		
		assertEquals("",50,attack.getToHit());
		assertEquals("",10,attack.getDamage());
		
		//testing player attack
		player = new Player();
		System.out.println("attacking with  (+10) 2D8 + 2");
		player.attack();
		player.attack();
		player.attack();
		
		player.setWeapon(new Weapon(0,1,6,0));
		player.setAP(100);
		System.out.println("attacking with  (+0) 1D6 + 0");
		player.attack();
		player.attack();
		player.attack();
		
		player.setWeapon(new Weapon(-5,3,12,-2));
		player.setAP(100);
		System.out.println("attacking with  (-5) 3D12 - 2");
		player.attack();
		player.attack();
		player.attack();
		
		player.setWeapon(new AmmoWeapon(0,2,6,1,6,2));
		player.setAP(100);
		player.attack();
		assertEquals("",5,((AmmoWeapon) player.getWeapon()).getShots());
		player.attack();
		assertEquals("",4,((AmmoWeapon) player.getWeapon()).getShots());
		player.reload();
		assertEquals("",6,((AmmoWeapon) player.getWeapon()).getShots());
		
		player.setWeapon(new AmmoWeapon(0,2,6,1,1,2));	
		player.setAP(100);
		player.attack();
		player.attack();
		assertEquals("",0,((AmmoWeapon) player.getWeapon()).getShots());
	}
	
	@Test
	public void APtests()
	{
		player = new Player();
		assertEquals("",100, player.getCurrentAP());
		
		player.move(50);
		assertEquals("",50,player.getCurrentAP());
		player.move(50);
		assertEquals("",0,player.getCurrentAP());
		player.move(50);
		assertEquals("",0,player.getCurrentAP());
		
		player.endTurn();
		assertEquals("",50,player.getCurrentAP());
		player.endTurn();
		assertEquals("",100,player.getCurrentAP());
		player.endTurn();
		assertEquals("",100,player.getCurrentAP());
		
		player.attack();
		assertEquals("",75,player.getCurrentAP());
		player.attack();
		assertEquals("",50,player.getCurrentAP());
		player.attack();
		assertEquals("",25,player.getCurrentAP());
		player.attack();
		assertEquals("",0,player.getCurrentAP());
		player.attack();
		assertEquals("",0,player.getCurrentAP());
		
		player = new Player();
		player.setWeapon(new Weapon(20,4,15,5,40,40,0));
		System.out.println("attacking with a (+20) 4D15 + 5");
		player.attack();
		assertEquals("",60,player.getCurrentAP());
		player.attack();
		assertEquals("",20,player.getCurrentAP());
		player.attack();
		assertEquals("",20,player.getCurrentAP());

	}
	@Test
	public void armorTests() throws SQLException
	{
		player = new Player();
		player.setArmor(Database.loadArmor("a1"));
		player.takeHit(45, 20);
		assertEquals("",100,player.getCurrentHP());
		player.takeHit(46, 20);
		assertEquals("",82,player.getCurrentHP());
		
		player = new Player();
		player.setArmor(Database.loadArmor("a2"));
		player.getArmor().getHP().setCurrent(2);
		player.takeHit(39, 10);
		assertEquals("",92,player.getCurrentHP());
		assertEquals("",0,player.getArmor().getHP().getCurrent());
	}
	
	@Test
	public void posionTests() throws SQLException
	{
		player = Database.loadPlayer("noGen");
		assertEquals("",100,player.getCurrentHP());
		player.addDOT(3, 1);
		player.endTurn();
		assertEquals("",97,player.getCurrentHP());
		player.endTurn();
		assertEquals("",95,player.getCurrentHP());
		player.endTurn();
		assertEquals("",94,player.getCurrentHP());
		player.endTurn();
		assertEquals("",94,player.getCurrentHP());
		
		
		player = Database.loadPlayer("noGen");
		assertEquals("",100,player.getCurrentHP());
		player.addDOT(4, 0.75);
		player.endTurn();
		assertEquals("",96,player.getCurrentHP());
		player.endTurn();
		assertEquals("",92,player.getCurrentHP());
		player.endTurn();
		assertEquals("",89,player.getCurrentHP());
		player.endTurn();
		assertEquals("",87,player.getCurrentHP());
		player.endTurn();
		assertEquals("",86,player.getCurrentHP());
		player.endTurn();
		assertEquals("",85,player.getCurrentHP());
		player.endTurn();
		assertEquals("",85,player.getCurrentHP());
		
		
		player = Database.loadPlayer("noGen");
		assertEquals("",100,player.getCurrentHP());
		player.addDOT(4, 1);
		player.endTurn();
		assertEquals("",96,player.getCurrentHP());
		player.addDOT(5, 1.5);
		player.endTurn();
		assertEquals("",88,player.getCurrentHP());
		player.endTurn();
		assertEquals("",82,player.getCurrentHP());
		player.endTurn();
		assertEquals("",79,player.getCurrentHP());
		player.endTurn();
		assertEquals("",78,player.getCurrentHP());
		player.endTurn();
		assertEquals("",78,player.getCurrentHP());
		
		player = Database.loadPlayer("mark");
		assertEquals("",125,player.getCurrentHP());
		player.addDOT(6, 1);
		player.endTurn();
		assertEquals("",120,player.getCurrentHP());
		player.endTurn();
		assertEquals("",116,player.getCurrentHP());
		player.endTurn();
		assertEquals("",113,player.getCurrentHP());
		player.endTurn();
		assertEquals("",111,player.getCurrentHP());
		player.endTurn();
		assertEquals("",110,player.getCurrentHP());
		assertEquals("",124,( (StatCounterSpeical) player.getHP()).getTmpMax());
		player.endTurn();
		assertEquals("",110,player.getCurrentHP());
		player.endTurn();
		assertEquals("",111,player.getCurrentHP());
				
	}
}
